/**
 入驻小区
 **/
(function(vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            adminInspectionTaskInfo: {
                tasks: [],
                total: 0,
                records: 1,
                moreCondition: false,
                taskId: '',
                stateTypes: [],
                conditions: {
                    planUserName: '',
                    inspectionPlanId: '',
                    inspectionPlanName: '',
                    actInsTime: '',
                    startTime: '',
                    endTime: '',
                    state: '',
                    communityId:'',
                    staffId:'',
                    orderByDesc: 'desc'
                }
            }
        },
        _initMethod: function() {
            //与字典表关联
            vc.getDict('inspection_task', "state", function(_data) {
                $that.adminInspectionTaskInfo.stateTypes = _data;
            });
            vc.emit('communityInspectionTree', 'initCommunityInspectionTree',{
                callName:'adminInspectionTask'
            })
            $that._initAdminInspectionTaskDateInfo();
            $that._listAdminInspectionTasks(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function() {
            vc.on('adminInspectionTask', 'notifyQuery', function(_param) {
                $that.adminInspectionTaskInfo.conditions.communityId = _param.communityId;
                $that.adminInspectionTaskInfo.conditions.inspectionPlanId = _param.inspectionPlanId;
                $that.adminInspectionTaskInfo.conditions.staffId = _param.staffId;
                $that._listAdminInspectionTasks(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('adminInspectionTask', 'listAdminInspectionTask', function(_param) {
                $that._listAdminInspectionTasks(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('adminInspectionTask', 'pageReload', function(_param) {
                location.reload();
            });
            vc.on('pagination', 'page_event', function(_currentPage) {
                $that._listAdminInspectionTasks(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _initAdminInspectionTaskDateInfo: function() {
                $('.startTime').datetimepicker({
                    language: 'zh-CN',
                    fontAwesome: 'fa',
                    format: 'yyyy-mm-dd hh:ii:ss',
                    initTime: true,
                    initialDate: new Date(),
                    autoClose: 1,
                    todayBtn: true
                });
                $('.startTime').datetimepicker()
                    .on('changeDate', function(ev) {
                        var value = $(".startTime").val();
                        $that.adminInspectionTaskInfo.conditions.startTime = value;
                    });
                $('.endTime').datetimepicker({
                    language: 'zh-CN',
                    fontAwesome: 'fa',
                    format: 'yyyy-mm-dd hh:ii:ss',
                    initTime: true,
                    initialDate: new Date(),
                    autoClose: 1,
                    todayBtn: true
                });
                $('.endTime').datetimepicker()
                    .on('changeDate', function(ev) {
                        var value = $(".endTime").val();
                        $that.adminInspectionTaskInfo.conditions.endTime = value;
                    });
            },
            _listAdminInspectionTasks: function(_page, _rows) {
                $that.adminInspectionTaskInfo.conditions.page = _page;
                $that.adminInspectionTaskInfo.conditions.row = _rows;
                let param = {
                    params: $that.adminInspectionTaskInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/inspectionTask.listAdminInspectionTasks',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.adminInspectionTaskInfo.total = _json.total;
                        $that.adminInspectionTaskInfo.records = _json.records;
                        $that.adminInspectionTaskInfo.tasks = _json.inspectionTasks;
                        vc.emit('pagination', 'init', {
                            total: $that.adminInspectionTaskInfo.records,
                            dataCount: $that.adminInspectionTaskInfo.total,
                            currentPage: _page
                        });
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAdminInspectionTaskDetail: function(_adminInspectionTask) {
               // vc.emit('adminInspectionTaskDetail', 'openAdminInspectionTaskDetail', _adminInspectionTask);
                window.open('/#/pages/inspection/adminInspectionTaskDetail?taskId='+_adminInspectionTask.taskId)
            },
           
            //查询
            _queryAdminInspectionTaskMethod: function() {
                $that._listAdminInspectionTasks(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetAdminInspectionTaskMethod: function() {
                $that.adminInspectionTaskInfo.conditions.planUserName = "";
                $that.adminInspectionTaskInfo.conditions.inspectionPlanId = "";
                $that.adminInspectionTaskInfo.conditions.inspectionPlanName = "";
                $that.adminInspectionTaskInfo.conditions.startTime = "";
                $that.adminInspectionTaskInfo.conditions.endTime = "";
                $that.adminInspectionTaskInfo.conditions.state = "";
                $that._listAdminInspectionTasks(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function() {
                if ($that.adminInspectionTaskInfo.moreCondition) {
                    $that.adminInspectionTaskInfo.moreCondition = false;
                } else {
                    $that.adminInspectionTaskInfo.moreCondition = true;
                }
            },
        }
    });
})(window.vc);